package com.koron.standard.patrol.bean.excel;

import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
import com.alibaba.excel.annotation.ExcelProperty;
import com.koron.common.core.util.CodeTools;
import com.koron.standard.patrol.bean.po.Patrol;
import com.koron.standard.patrol.bean.po.PatrolCheck;
import com.koron.standard.patrol.bean.po.PatrolRecord;
import com.koron.standard.patrol.excel.PatrolStringStringConvertor;
import lombok.Data;

/**
 * @author jzp
 * @since 2022/5/16
 */
@ExcelIgnoreUnannotated
@Data
public class PatrolExcel {

    // @ExcelProperty(value = "设备分类编码，转化为设备分类id")
    @ExcelProperty(index = 0)
    private String typeId;

    // @ExcelProperty(value = "设备分类名称")
    @ExcelProperty(index = 1)
    private String typeName;

    // @ExcelProperty(value = "标题")
    @ExcelProperty(index = 2)
    private String name;

    // @ApiModelProperty("检查项-设备运行状态。运行中0，未运行1")
    @ExcelProperty(index = 3, converter = PatrolStringStringConvertor.class)
    private Integer checkStatus;

    // @ApiModelProperty("检查项-名称")
    @ExcelProperty(index = 4)
    private String checkName;

    // @ApiModelProperty("检查项-标准")
    @ExcelProperty(index = 5)
    private String checkContent;

    // @ApiModelProperty("数据记录项-设备运行状态。运行中0，未运行1")
    @ExcelProperty(index = 6, converter = PatrolStringStringConvertor.class)
    private Integer recordStatus;

    // @ApiModelProperty("记录项名称")
    @ExcelProperty(index = 7)
    private String recordName;

    // @ApiModelProperty("记录项单位")
    @ExcelProperty(index = 8)
    private String recordUnit;

    // @ApiModelProperty("默认值")
    @ExcelProperty(index = 9)
    private String recordDefaultValue;

    // @ApiModelProperty("数据标准")
    @ExcelProperty(index = 10)
    private String recordDataLimit;

    public Patrol buildPatrol() {
        Patrol patrol = new Patrol();
        patrol.setId(CodeTools.getCode32());
        patrol.setName(name);
        patrol.setTypeId(typeId);
        patrol.setPublicStatus(0);
        patrol.setStatus(1);
        // code, appid, sort
        return patrol;
    }

    public PatrolCheck buildPatrolCheck(String patrolId, Integer sort, Integer checkStatus) {
        PatrolCheck check = new PatrolCheck();
        check.setPatrolId(patrolId);
        check.setStatus(this.checkStatus == null ? checkStatus : this.checkStatus);
        check.setName(checkName);
        check.setContent(checkContent);
        check.setSort(sort);
        return check;
    }

    public PatrolRecord buildPatrolRecord(String patrolId, Integer sort, Integer recordStatus) {
        PatrolRecord record = new PatrolRecord();
        record.setPatrolId(patrolId);
        record.setStatus(this.recordStatus == null ? recordStatus : this.recordStatus);
        record.setName(recordName);
        record.setUnit(recordUnit);
        record.setDefaultValue(recordDefaultValue);
        record.setDataLimit(recordDataLimit);
        record.setSort(sort);
        return record;
    }

}
